// Lab3.cpp : Defines the entry point for the console application.
//

#include <iostream>

using namespace std;

class Array{
    
    int * p;
    size_t capacity;
    size_t size;
 
    Array(const Array& arB, size_t capacity):capacity(capacity){

	p = new int[capacity];
	size = arB.size;
	
	for(size_t i=0; i < capacity; i++){
	    set(i, arB.get(i));
	}

    }

public:

    explicit Array(size_t capacity):capacity(capacity), size(0){	
	p = new int[capacity];
	for(size_t i = 0; i < capacity; i++){
	    set(i, 0);
	}

    }

    Array(const Array& arB):capacity(arB.capacity){

	p = new int[capacity];
	size = arB.size;
	
	for(size_t i=0; i < capacity; i++){
	    set(i, arB.get(i));
	}
	
    }
    
    Array & operator=(const Array& arB){
	
	if(&arB == this)
	    return *this;

	Array r(arB);	
	swapa(r);

	return *this;

    }

    

    void push_back(int i){
	
	if(size == capacity)
	    allocate();

	p[size] = i;
	size++;

    }
    
    
    int get(size_t i) const{
	return p[i]; 
    }

    int set(size_t i, int v){
	return p[i] = v;
    }

    void showElements() const {

	for(size_t i = 0; i < size; i++){
	    cout << get(i) << " ";
	}

    }

    ~Array(){
	delete[] p;
    }


private:

    void swapa(Array & a){
	
	swap(capacity, a.capacity);
	swap(size, a.size);
	swap(p, a.p);	

    }


    void allocate(){
    
	Array tmp(*this, capacity * 2);	
	swapa(tmp);
	

    }

};

int main(){

       
    Array a(10);
    Array b(10);    
        
    cout << "a: ";
    a.showElements();
    cout << endl;

    for(size_t i = 0; i < 20; i++){
	b.push_back(i * i);
    }

    cout << "b: ";
    b.showElements();
    cout << endl;

    Array ba(b);
    cout << "ba: ";
    ba.showElements();
    cout << endl;

    cout << "a = b";
    a = b;
    cout << endl;
    
    cout << "a: ";
    a.showElements();
    cout << endl;
    cout << "b: ";
    b.showElements();
    cout << endl;



    int ii = 0;
    cin >> ii;
    return 0;


}
